package com.kk.framework.ui;

import java.util.Collection;
import java.util.List;

import org.zkoss.zk.ui.Execution;
import org.zkoss.zk.ui.util.ThemeProvider;

import com.kk.framework.session.CookieManager;
import com.kk.framework.util.Constants;
import com.kk.framework.util.StringUtils;

public class SimpleThemeProvider implements ThemeProvider
{
	public static String getSkinCookie(Execution exec)
	{
		String cookie = CookieManager.getCookie(exec, "THEME_COOKIE");
		return cookie;
	}

	public static void  setSkinCookie(Execution exec, String themeCode)
	{
	    CookieManager.setCookie(exec, "THEME_COOKIE", themeCode);
	}
	
	@Override
	public String beforeWidgetCSS(Execution arg0, String arg1)
	{
		return arg1;
	}

	@Override
	public Collection<Object> getThemeURIs(Execution exec, List<Object> uris)
	{
		uris.add("./theme/theme_other.css");
		if (Constants.THEME_BLUE.equals(getSkinCookie(exec)) || StringUtils.isEmpty(getSkinCookie(exec)))
		{
			if (exec.getDesktop() == null)
			{
				return uris;
			}
			if (exec.getDesktop().getCurrentDirectory().startsWith("/login") || exec.getDesktop().getCurrentDirectory().startsWith("/utils"))
			{
				uris.add("../theme/blue/frame.css");
				uris.add("../theme/blue/login.css");
				uris.add("../theme/blue/bootstrap/css/bootstrap.css");
			}
			else
			{
				uris.add("./theme/blue/bootstrap/css/bootstrap.css");
				uris.add("./theme/blue/bootstrap/css/bootstrap-theme.css");
				uris.add("./theme/blue/frame.css");
				uris.add("./theme/blue/component.css");
				uris.add("./theme/blue/module-gis.css");
				uris.add("./theme/blue/module-sys-cfg.css");
				uris.add("./theme/blue/module-task.css");
			}
		}
		else if (Constants.THEME_BROWN.equals(getSkinCookie(exec)) || StringUtils.isEmpty(getSkinCookie(exec)))
		{
		    if(exec.getDesktop() == null)
		    {
		        return uris;
		    }
		    if(exec.getDesktop().getCurrentDirectory().startsWith("/login") || exec.getDesktop().getCurrentDirectory().startsWith("/utils"))
		    {
                uris.add("../theme/brown/frame.css");
                uris.add("../theme/brown/login.css");
                uris.add("../theme/brown/bootstrap/css/bootstrap.css");
		    }
		    else
		    {
		        uris.add("./theme/brown/bootstrap/css/bootstrap.css");
                uris.add("./theme/brown/bootstrap/css/bootstrap-theme.css");
                uris.add("./theme/brown/frame.css");
                uris.add("./theme/brown/component.css");
                uris.add("./theme/brown/module-gis.css");
                uris.add("./theme/brown/module-sys-cfg.css");
                uris.add("./theme/brown/module-task.css");
		    }
		}
	    else if (Constants.THEME_PINK.equals(getSkinCookie(exec)) || StringUtils.isEmpty(getSkinCookie(exec)))
	    {
	         if(exec.getDesktop() == null)
	         {
	             return uris;
	         }
	         if(exec.getDesktop().getCurrentDirectory().startsWith("/login") || exec.getDesktop().getCurrentDirectory().startsWith("/utils"))
	         {
	             uris.add("../theme/pink/frame.css");
	             uris.add("../theme/pink/login.css");
	             uris.add("../theme/pink/bootstrap/css/bootstrap.css");
	         }
	         else
	         {
	             uris.add("./theme/pink/bootstrap/css/bootstrap.css");
	             uris.add("./theme/pink/bootstrap/css/bootstrap-theme.css");
	             uris.add("./theme/pink/frame.css");
	             uris.add("./theme/pink/component.css");
	             uris.add("./theme/pink/module-gis.css");
	             uris.add("./theme/pink/module-sys-cfg.css");
	             uris.add("./theme/pink/module-task.css");
	          }
	     }
        else if (Constants.THEME_GREEN.equals(getSkinCookie(exec)) || StringUtils.isEmpty(getSkinCookie(exec)))
        {
            if(exec.getDesktop() == null)
            {
                return uris;
            }
            if(exec.getDesktop().getCurrentDirectory().startsWith("/login") || exec.getDesktop().getCurrentDirectory().startsWith("/utils"))
            {
                uris.add("../theme/green/frame.css");
                uris.add("../theme/green/login.css");
                uris.add("../theme/green/bootstrap/css/bootstrap.css");
            }
            else
            {
                uris.add("./theme/green/bootstrap/css/bootstrap.css");
                uris.add("./theme/green/bootstrap/css/bootstrap-theme.css");
                uris.add("./theme/green/frame.css");
                uris.add("./theme/green/component.css");
                uris.add("./theme/green/module-gis.css");
                uris.add("./theme/green/module-sys-cfg.css");
                uris.add("./theme/green/module-task.css");
            }
        }
        else if (Constants.THEME_PURPLE.equals(getSkinCookie(exec)) || StringUtils.isEmpty(getSkinCookie(exec)))
        {
            if(exec.getDesktop() == null)
            {
                return uris;
            }
            if(exec.getDesktop().getCurrentDirectory().startsWith("/login") || exec.getDesktop().getCurrentDirectory().startsWith("/utils"))
            {
                uris.add("../theme/purple/frame.css");
                uris.add("../theme/purple/login.css");
                uris.add("../theme/purple/bootstrap/css/bootstrap.css");
            }
            else
            {
                uris.add("./theme/purple/bootstrap/css/bootstrap.css");
                uris.add("./theme/purple/bootstrap/css/bootstrap-theme.css");
                uris.add("./theme/purple/frame.css");
                uris.add("./theme/purple/component.css");
                uris.add("./theme/purple/module-gis.css");
                uris.add("./theme/purple/module-sys-cfg.css");
                uris.add("./theme/purple/module-task.css");
            }
        }
        else if (Constants.THEME_BLACK.equals(getSkinCookie(exec)) || StringUtils.isEmpty(getSkinCookie(exec)))
        {
            if(exec.getDesktop() == null)
            {
                return uris;
            }
            if(exec.getDesktop().getCurrentDirectory().startsWith("/login") || exec.getDesktop().getCurrentDirectory().startsWith("/utils"))
            {
                uris.add("../theme/black/frame.css");
                uris.add("../theme/black/login.css");
                uris.add("../theme/black/bootstrap/css/bootstrap.css");
            }
            else
            {
                uris.add("./theme/black/bootstrap/css/bootstrap.css");
                uris.add("./theme/black/bootstrap/css/bootstrap-theme.css");
                uris.add("./theme/black/frame.css");
                uris.add("./theme/black/component.css");
                uris.add("./theme/black/module-gis.css");
                uris.add("./theme/black/module-sys-cfg.css");
                uris.add("./theme/black/module-task.css");
            }
        }
		return uris;
	}

	@Override
	public int getWCSCacheControl(Execution arg0, String arg1)
	{
		return 0;
	}

	@Override
	public String beforeWCS(Execution arg0, String arg1)
	{
		return arg1;
	}
}